<template>
  <el-dialog
    v-if="visible"
    v-dialogDrag
    modal
    :visible.sync="visible"
    :close-on-click-modal="false"
    width="70%"
  >
    <div slot="title" class="dialog-header">物资出库详情</div>
    <div class="table-name-content">物资领用详情</div>
    <wz-table :columns="mcDetails" :use-index="true" :table-data="fileData">
      <template #outputType="{ row }">
        <div>
          {{ outputType(row.outputType) }}
        </div>
      </template>
    </wz-table>
    <div class="table-name-content mt-10">资源资产编码</div>
    <wz-table
      :columns="resourceCoding"
      :use-index="true"
      :table-data="assetsFileData"
    >
      <template #scanConfirm="{ row }">
        <div>
          {{ scanConfirm(row) }}
        </div>
      </template>
      <template #labelId="{ row }">
        <div class="click-row" @click="jump(row)">
          {{ row.labelId }}
        </div>
      </template>
    </wz-table>
  </el-dialog>
</template>

<script>
import $ from 'jquery'

const Material_Collection_Details = [
    {
        label: '出库订单号',
        prop: 'orderId',
        elProps: {
            width: '100px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '出库明细行号',
        prop: 'osDetailId',
        elProps: {
            width: '100px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '物料编码',
        prop: 'categoryCode',
        elProps: {
            width: '100px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '物料名称',
        prop: 'categoryName',
        elProps: {
            'show-overflow-tooltip': true
        }
    },
    {
        label: '出库数量',
        prop: 'osAmount',
        elProps: {
            width: '100px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '计量单位',
        prop: 'unit',
        elProps: {
            width: '100px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '是否利旧资产',
        prop: 'outputType',
        elProps: {
            width: '100px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '不含税单价',
        prop: 'price',
        elProps: {
            width: '100px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '含税总金额',
        prop: 'totalTaxAmount',
        elProps: {
            width: '100px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '领用人',
        prop: 'createBy',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '出库时间',
        prop: 'osTime',
        elProps: {
            width: '140px',
            'show-overflow-tooltip': true
        }
    }
]
const RESOURCE_ASSET_CODING = [
    { label: '资源资产编码', prop: 'sourceAssetCode' },
    { label: '标签ID', prop: 'labelId' },
    { label: '赋码贴签方式', prop: 'fromPhotoName' },
    { label: '赋码贴签人', prop: 'labelUser' },
    { label: '是否到货确认', prop: 'scanConfirm' },
    { label: '到货确认人', prop: 'scanConfirmUser' },
    { label: '经纬度', prop: 'longitude' }
]
import wzTable from '../components/cTable.vue'
import { queryReceiveList, queryAssetLabelDatailListSynt, openAssetFull } from '@/api/material.js'
export default {
    name: 'MaterialOutDialog',
    components: { wzTable },
    props: {
        materialRemovalVisible: {
            type: Boolean,
            default: false
        },
        currentRow: {
            type: Object,
            default: () => ({ })
        }
    },
    data() {
        return {
            mcDetails: [],
            resourceCoding: [],
            fileData: [],
            assetsFileData: [],
            visible: false,
            url: '',
            token: '',
            userId: '',
            acctId: ''
        }
    },
    computed: {
        query() {
            return this.$route.query
        }
    },
    watch: {
        materialRemovalVisible: {
            handler(value) {
                this.visible = value
            },
            immediate: true
        },
        visible(value) {
            this.$emit('update:materialRemovalVisible', value)
        }
    },
    async mounted() {
        this.mcDetails = JSON.parse(
            JSON.stringify(Material_Collection_Details)
        )
        this.resourceCoding = JSON.parse(JSON.stringify(RESOURCE_ASSET_CODING))
        const res = await queryReceiveList({
            prjId: this.query.prjId,
            categoryCode: this.currentRow.categoryCode
        })
        if (+res.code === 200) {
            this.fileData = res.data
        }
        const resAssets = await queryAssetLabelDatailListSynt({
            prjId: this.query.prjId,
            categoryCode: this.currentRow.categoryCode
        })
          if (+res.code === 200) {
            this.assetsFileData = resAssets.data
        }
        const openAssetFullRes = await openAssetFull()
        console.log(openAssetFullRes)
        if (+openAssetFullRes.code === 200) {
            this.url = openAssetFullRes.data.url
            this.token = openAssetFullRes.data.token
            this.userId = openAssetFullRes.data.userId
            this.acctId = openAssetFullRes.data.acctId
        }
    },
    methods: {
        outputType(outputType) {
            return +outputType === 9 ? '是' : '否'
        },
        scanConfirm(row) {
            const keyValue = {
                0: '否',
                1: '是'
            }
            return keyValue[+row.scanConfirm]
        },
        // 点击标签id跳转经分系统
        jump(row) {
            console.log(row)
            const toUrl = `${this.url}ctb_thematic_web/newTowerSkip/assetsRecordNew?res_id=${row.labelId}&resourceAssetCode=${row.sourceAssetCode}`
            const params = {}
            params.pwdaToken = this.token
            params.acctId = this.acctId
            params.userName = this.userId
            const newWin = window.open()
            const form = $("<form method='post'></form>")
            form.attr({ action: toUrl })
            $.each(params, function(key, value) {
                const input = $("<input type='hidden' >")
                input.attr({ name: key })
                input.val(value)
                form.append(input)
            })
            form.appendTo(newWin.document.body)
            form.submit()
        }
    }
}
</script>
<style lang="scss" scoped>

.mt-10 {
    margin-top: 10px;
}

.click-row {
    color: #53c7f8;
    cursor: pointer;
}
</style>
